//
//  MineTaskListCell.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/30.
//  Copyright © 2016年 SpaceZ. All rights reserved.
//

#import "MineTaskListCell.h"

@interface MineTaskListCell()

@property (nonatomic, strong) UIImageView *cover_image_view;
@property (nonatomic, strong) UIButton *right_button;
@property (nonatomic, strong) UILabel *title_label;
@property (nonatomic, strong) UILabel *desc_label;
@property (nonatomic, strong) UILabel *date_label;

@end

@implementation MineTaskListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self makeTaskListViewCell];
        
    }
    return self;
}

- (void)makeTaskListViewCell
{
    //    UILabel *gift_title_label = [UILabel new];
    //    gift_title_label.text = @"奖    励";
    //    gift_title_label.textColor = [UIColor blackColor];
    //    gift_title_label.font = [UIFont systemFontOfSize:18.0f];
    //    [self.contentView addSubview:gift_title_label];
    //    [gift_title_label mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.mas_equalTo(20);
    //        make.top.mas_equalTo(self.mas_centerY).mas_offset(-30);
    //        make.size.mas_equalTo(CGSizeMake(65, 25));
    //    }];
    
    UIImageView *gift_title_image = [UIImageView new];
    //    gift_title_image.image = [UIImage imageNamed:@"task_gift_title_image"];
    [self.contentView addSubview:gift_title_image];
    [gift_title_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.mas_centerY).mas_offset(-30);
        make.size.mas_equalTo(CGSizeMake(60, 36));
        
    }];
    
    _cover_image_view = [UIImageView new];
    _cover_image_view.layer.masksToBounds = YES;
    _cover_image_view.layer.borderWidth = 0;
    _cover_image_view.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_cover_image_view];
    [_cover_image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.left.mas_equalTo(gift_title_image.mas_right).mas_offset(20);
        make.width.mas_equalTo(120);
    }];
    
    _right_button = [UIButton new];
    _right_button.backgroundColor = [UIColor whiteColor];
    _right_button.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
    _right_button.layer.shadowOffset = CGSizeMake(2,2);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    _right_button.layer.shadowOpacity = 0.3;
    _right_button.layer.shadowRadius = 2;
    _right_button.titleLabel.font = [UIFont systemFontOfSize:16.0f];
    [_right_button addTarget:self action:@selector(clickRightButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_right_button];
    [_right_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(90, 36));
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self);
    }];
    
    _title_label = [UILabel new];
    _title_label.textColor = [UIColor blackColor];
    _title_label.font = [UIFont systemFontOfSize:18.0f];
    [self.contentView addSubview:_title_label];
    [_title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(_cover_image_view.mas_right).mas_offset(20);
        make.right.mas_equalTo(_right_button.mas_left).mas_offset(-20);
        make.height.mas_equalTo(30);
    }];
    
    _desc_label = [UILabel new];
    _desc_label.textColor = RGB(200, 200, 200);
    _desc_label.font = [UIFont systemFontOfSize:15.0f];
    [self.contentView addSubview:_desc_label];
    [_desc_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_title_label.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(_cover_image_view.mas_right).mas_offset(20);
        make.right.mas_equalTo(_right_button.mas_left).mas_offset(-20);
        make.height.mas_equalTo(30);
    }];
    
    _date_label = [UILabel new];
    _date_label.textColor = RGB(200, 200, 200);
    _date_label.font = [UIFont systemFontOfSize:15.0f];
    [self.contentView addSubview:_date_label];
    [_date_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_desc_label.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(_cover_image_view.mas_right).mas_offset(20);
        make.right.mas_equalTo(_right_button.mas_left).mas_offset(-20);
        make.height.mas_equalTo(30);
    }];
}

- (void)loadMineTaskListCell:(TaskModel *)model
{
    [_cover_image_view sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseIp,model.image]] placeholderImage:nil];
    
    [self setRightButtonState:@"查    看" color:[UIColor blackColor]];
    
    
    _title_label.text = model.name;
    _desc_label.text = [NSString stringWithFormat:@"发起人:%@",model.friendInfo.username];
    
    _date_label.text = [NSString stringWithFormat:@"任务周期:%@  -  %@",[ZZDateFormat fetch10Date:model.startdate format:@"yyyy.MM.dd"],[ZZDateFormat fetch10Date:model.enddate format:@"yyyy.MM.dd"]];
}

- (void)setRightButtonState:(NSString *)title color:(UIColor *)color
{
    [_right_button setTitle:title forState:UIControlStateNormal];
    [_right_button setTitleColor:color forState:UIControlStateNormal];
}

- (void)clickRightButton:(UIButton *)button
{
    if (self.selectCellBlock) {
        self.selectCellBlock();
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
